﻿using System;

namespace UniRx
{
	// Token: 0x02000410 RID: 1040
	public class ReactiveCommand<T> : IReactiveCommand<T>, IDisposable, IObservable<T>
	{
		// Token: 0x06001558 RID: 5464 RVA: 0x0005F062 File Offset: 0x0005D462
		public ReactiveCommand()
		{
			this.canExecute = new ReactiveProperty<bool>(true);
			this.canExecuteSubscription = Disposable.Empty;
		}

		// Token: 0x06001559 RID: 5465 RVA: 0x0005F08C File Offset: 0x0005D48C
		public ReactiveCommand(IObservable<bool> canExecuteSource, bool initialValue = true)
		{
			this.canExecute = new ReactiveProperty<bool>(initialValue);
			this.canExecuteSubscription = canExecuteSource.DistinctUntilChanged<bool>().SubscribeWithState(this.canExecute, delegate(bool b, ReactiveProperty<bool> c)
			{
				c.Value = b;
			});
		}

		// Token: 0x1700019A RID: 410
		// (get) Token: 0x0600155A RID: 5466 RVA: 0x0005F0EA File Offset: 0x0005D4EA
		public IReadOnlyReactiveProperty<bool> CanExecute
		{
			get
			{
				return this.canExecute;
			}
		}

		// Token: 0x1700019B RID: 411
		// (get) Token: 0x0600155B RID: 5467 RVA: 0x0005F0F2 File Offset: 0x0005D4F2
		// (set) Token: 0x0600155C RID: 5468 RVA: 0x0005F0FA File Offset: 0x0005D4FA
		public bool IsDisposed { get; private set; }

		// Token: 0x0600155D RID: 5469 RVA: 0x0005F103 File Offset: 0x0005D503
		public bool Execute(T parameter)
		{
			if (this.canExecute.Value)
			{
				this.trigger.OnNext(parameter);
				return true;
			}
			return false;
		}

		// Token: 0x0600155E RID: 5470 RVA: 0x0005F124 File Offset: 0x0005D524
		public void ForceExecute(T parameter)
		{
			this.trigger.OnNext(parameter);
		}

		// Token: 0x0600155F RID: 5471 RVA: 0x0005F132 File Offset: 0x0005D532
		public IDisposable Subscribe(IObserver<T> observer)
		{
			return this.trigger.Subscribe(observer);
		}

		// Token: 0x06001560 RID: 5472 RVA: 0x0005F140 File Offset: 0x0005D540
		public void Dispose()
		{
			if (this.IsDisposed)
			{
				return;
			}
			this.IsDisposed = true;
			this.canExecute.Dispose();
			this.trigger.OnCompleted();
			this.trigger.Dispose();
			this.canExecuteSubscription.Dispose();
		}

		// Token: 0x04000C4C RID: 3148
		private readonly Subject<T> trigger = new Subject<T>();

		// Token: 0x04000C4D RID: 3149
		private readonly IDisposable canExecuteSubscription;

		// Token: 0x04000C4E RID: 3150
		private ReactiveProperty<bool> canExecute;
	}
}
